#include "main.h"
#include "stm32f0xx.h"
#include "adc.h"
#include "si24r1.h"
#include "timer.h"

uint32_t AdcVolt = 0;
u8 Tpack_return = 0,Rpack_return = 0;
u8 R_FLAG = 0;


#define RX_MODE		1
#define TX_MODE 	0

int temp = 0,ii = 0;

int main(void)
{	
	#if	TX_MODE
	u8 buf[4] = {0,0,0,0};
	ADC_GPIO_Init();
	ADC_Configuration();
	SI24R1_Init();
	TIMER_Init();
	Delay_100ms(2);
	//SI24R1_RX_Mode();
	//SI24R1_TX_Mode();
	while(1)
	{
//		SI24R1_Init();
//		AdcVolt = ADC_Check();
//		buf[0] = AdcVolt & 0xff;
//		buf[1] = (AdcVolt >> 8) & 0xff;
//		buf[2] = (AdcVolt >> 16) & 0xff;
//		buf[3] = AdcVolt >> 24;
		buf[0] = buf[0]++;	buf[1] = buf[1]++;	buf[2] = buf[2]++;	buf[3] = buf[3]++;
		Tpack_return = SI24R1_TxPacket(buf);
		Delay_100ms(2);
	}
	#elif RX_MODE
	u8 buf1[4] = {0};
	SI24R1_Init();
	TIMER_Init();
	Delay_100ms(2);
	//SI24R1_RX_Mode();
	R_FLAG = 0;
	
	while(1)
	{
//		SI24R1_Init();
		SI24R1_RX_Mode();
		//while(IRQ == 1);
		Delay_100ms(1);
//		if(R_FLAG == 0) SI24R1_RxPacket_FLAG(buf1);
//		else 
			Rpack_return = SI24R1_RxPacket(buf1);
		if(temp != buf1[0]) ii++;
		temp = buf1[0];
		AdcVolt = buf1[0] | (buf1[1] << 8);
	}
	#endif
}

